<?php
/* Day view */

$month = $_GET['month'];
$year = $_GET['year'];
$day = $_GET['day'];
$title = "Events for " . date('F j, Y', strtotime("$year-$month-$day"));
include('includes/header.php');
$events = get_events($day,$month,$year);
if (sizeof($events) == 0) { ?>
<p>No events found.  <a href='/calendar/add/'>Add one?</a></p>
<?php } else { ?>


<div class='day-view'>
	<?php $aevents =get_allday_events($day,$month,$year);
	if (sizeof($aevents) > 0) { ?>
	<div class='allday'>
		<?php foreach ($aevents as $event) { ?>
			<div class='event'><a href='<?php echo $event['slug'];?>/?height=300&width=450' title='<?php echo $event['title']; ?>' class="thickbox" >
			<?php echo $event['title']; ?>
			</a></div>
		<?php } ?>
	</div>
	<?php } ?>
	<div class='inner'>
		<div class='times'>
			<?php 
			$start = get_earliest_event($day,$month,$year);
			$end = 24;
			for ($h=$start; $h<=$end; $h++) { 
				for ($m=0; $m<60; $m=$m+15) {
			?>
				<div class='time <?php if ($m==0) echo " hour"; else echo " minute";?>'>
				<?php if ($m==0) echo format_time("$h:$m:00"); else echo "<div class='dash'></div>";?>
				</div> 
				<?php } ?>
			<?php } ?> 
		</div>
		<?php 
		$curr_col = 0;
		foreach ($events as $event) { 
		if (should_display_time($event,$year,$month,$day)) { 
		$stime = explode(":",$event['starttime']);
		$diff = get_time_difference($event['startdate'] . " " . $event['starttime'],$event['enddate'] . " " . $event['endtime']);
		$height = time_to_pixels($diff['hours'],$diff['minutes']);
		$loc = time_to_pixels($stime[0]-$start,$stime[1],null);
		$col = get_conflicts($event,$day,$month,$year);
		$width = (430 - (($col+1) * 10)) / $col+1 ;
		?>
		<div class='event' style='margin-top: <?php echo $loc; ?>px; width: <?php echo $width; ?>px; height: <?php echo $height; ?>px; margin-left: <?php echo 30+($curr_col*$width)+($curr_col*10); ?>px' >
			<div class='event-head'>
			<a href='<?php echo $event['slug'];?>/?height=300&width=450' title='<?php echo $event['title']; ?>' class="thickbox" >
			<?php echo $event['title']; ?>
			</a>
			</div>
			<?php echo format_time($event['starttime']); ?> -
			<?php echo format_time($event['endtime']); ?>
			<div class='clear'> </div>
		</div>
		<?php 
		$curr_col++;
		} 
		if ($curr_col == $col) $curr_col = 0;
		} ?>
		<div class='clear'></div>
	</div>
	
</div>
<?php } ?>
<?php include('includes/footer.php');?>